package com.yyplatform.admin.infra.web.shiro;

import org.apache.shiro.SecurityUtils;
import org.apache.shiro.subject.Subject;

/**
 * Created on 2024-09-14
 */
public class CurrentUserHolder {


    public static Subject getSubject() {
        return SecurityUtils.getSubject();
    }


    public static CurrentUser getCurrentUser() {
        Subject subject = getSubject();
        if (subject == null) {
            return new CurrentUser();
        }

        CurrentUser user = (CurrentUser) subject.getPrincipal();
        if (user == null) {
            return new CurrentUser();
        }

        return user;
    }

    public static long getUserId() {
        return getCurrentUser().getId();
    }


}

